From 0da6c943c818715762856d8050f3ad5ace683ca8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 14 Jun 2015 22:13:08 -0700 Subject: [PATCH] Fix build on MSVC * Download all snapshots and such from static.rust-lang.org (drive-by fix) * Update dependencies to work and build on MSVC * ssh2-sys uses `nmake` to build libssh2 * libgit2-sys uses `cmake` to build libgit2 * curl-sys uses `nmake` to build libcurl * libz-sys uses `nmake` to build zlib * miniz-sys uses `gcc-rs` to drive `cl.exe` manually * term updated to pick up windows-specific deps on MSVC * Updated .travis.install.deps.sh to install MSVC target libraries on Windows, so the compiler can be used to target MSVC. A 64-bit target is now used by default as well. * Updated the configure script and Makefile to set appropriate environment variables to build Cargo from a MSYS shell with a MSVC target. This is similar to how Rust bootstraps on MSVC as well. With this commit Cargo can successfully bootstrap itself on MSVC (use the MSVC product to build itself again). The tests currently do not pass because unwinding is not implemented, but soon! --- .travis.install.deps.sh | 76 +++++++++++++++++++++++------------------ Cargo.lock | 49 +++++++++++++------------- Cargo.toml | 12 +++---- Makefile.in | 13 +++++++ configure | 46 +++++++++++++++++++++++++ src/etc/dl-snapshot.py | 2 +- 6 files changed, 131 insertions(+), 67 deletions(-) diff --git a/.travis.install.deps.sh b/.travis.install.deps.sh index 0fc51e541..8e1eb0008 100755 --- a/.travis.install.deps.sh +++ b/.travis.install.deps.sh @@ -20,48 +20,56 @@ if [ "${TRAVIS}" = "true" ] && [ "${target}" = "unknown-linux-gnu" ]; then sudo apt-get install g++-multilib lib32stdc++6 fi -url=https://static-rust-lang-org.s3.amazonaws.com/dist/`cat src/rustversion.txt` +url=https://static.rust-lang.org/dist/`cat src/rustversion.txt` -# Install both 64 and 32 bit libraries. Apparently travis barfs if you try to -# just install the right ones? This should enable cross compilation in the -# future anyway. +# On unix hosts install both 32 and 64-bit libraries, but respect BITS to +# determine what arch should be used by default. On windows we don't use 32/64 +# libraries, but instead we install msvc as an alternate architecture. if [ -z "${windows}" ]; then - rm -rf rustc *.tar.gz - curl -O $url/rustc-nightly-i686-$target.tar.gz - curl -O $url/rustc-nightly-x86_64-$target.tar.gz - tar xfz rustc-nightly-i686-$target.tar.gz - tar xfz rustc-nightly-x86_64-$target.tar.gz - if [ "${BITS}" = "32" ]; then - src=x86_64 - dst=i686 + cargo_extra=x86_64-$target + cargo_host=i686-$target else - src=i686 - dst=x86_64 + cargo_extra=i686-$target + cargo_host=x86_64-$target fi - cp -r rustc-nightly-$src-$target/rustc/lib/rustlib/$src-$target \ - rustc-nightly-$dst-$target/rustc/lib/rustlib - (cd rustc-nightly-$dst-$target && \ - find rustc/lib/rustlib/$src-$target/lib -type f | \ - sed 's/^rustc\//file:/' >> rustc/manifest.in) - - ./rustc-nightly-$dst-$target/install.sh --prefix=rustc - rm -rf rustc-nightly-$src-$target - rm -rf rustc-nightly-$dst-$target - rm -f rustc-nightly-i686-$target.tar.gz - rm -f rustc-nightly-x86_64-$target.tar.gz + libdir=lib else - rm -rf rustc *.exe *.tar.gz - if [ "${BITS}" = "64" ]; then - triple=x86_64-pc-windows-gnu + if [ "${BITS}" = "32" ]; then + cargo_host=i686-pc-windows-gnu + elif [ "${MSVC}" = "1" ]; then + cargo_host=x86_64-pc-windows-msvc else - triple=i686-pc-windows-gnu + cargo_host=x86_64-pc-windows-gnu + cargo_extra=x86_64-pc-windows-msvc fi - curl -O $url/rustc-nightly-$triple.tar.gz - tar xfz rustc-nightly-$triple.tar.gz - ./rustc-nightly-$triple/install.sh --prefix=rustc - rm -rf rustc-nightly-$triple - rm -f rustc-nightly-$triple.tar.gz + libdir=bin fi +rm -rf rustc *.tar.gz +curl -O $url/rustc-nightly-$cargo_host.tar.gz +tar xfz rustc-nightly-$cargo_host.tar.gz + +if [ ! -z "${cargo_extra}" ]; then + curl -O $url/rustc-nightly-$cargo_extra.tar.gz + tar xfz rustc-nightly-$cargo_extra.tar.gz + + cp -r rustc-nightly-$cargo_extra/rustc/$libdir/rustlib/$cargo_extra \ + rustc-nightly-$cargo_host/rustc/$libdir/rustlib + cp -r rustc-nightly-$cargo_extra/rustc/$libdir/rustlib/$cargo_extra/bin \ + rustc-nightly-$cargo_host/rustc/$libdir/rustlib/$cargo_host + (cd rustc-nightly-$cargo_host && \ + find rustc/$libdir/rustlib/$cargo_extra -type f | \ + sed 's/^rustc\//file:/' >> rustc/manifest.in) + (cd rustc-nightly-$cargo_host && \ + find rustc/$libdir/rustlib/$cargo_host/bin -type f | \ + sed 's/^rustc\//file:/' >> rustc/manifest.in) + rm -rf rustc-nightly-$cargo_extra + rm -f rustc-nightly-$cargo_extra.tar.gz +fi + +./rustc-nightly-$cargo_host/install.sh --prefix=rustc +rm -rf rustc-nightly-$cargo_host +rm -f rustc-nightly-$cargo_host.tar.gz + set +x diff --git a/Cargo.lock b/Cargo.lock index 6ea192d32..2a0a9a44a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ "hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git)", "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "registry 0.1.0", "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -26,10 +26,10 @@ dependencies = [ "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "threadpool 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -37,7 +37,7 @@ name = "advapi32-sys" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -55,7 +55,7 @@ name = "curl" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curl-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "curl-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -64,11 +64,11 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.1.22" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "gcc" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -118,7 +118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -148,7 +148,7 @@ name = "kernel32-sys" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -158,12 +158,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.2.14" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libssh2-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libssh2-sys 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -178,18 +178,18 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libz-sys" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -214,16 +214,15 @@ name = "miniz-sys" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" -version = "0.1.0" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -232,7 +231,7 @@ name = "openssl-sys" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libressl-pnacl-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -309,7 +308,7 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -319,10 +318,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -345,7 +344,7 @@ dependencies = [ [[package]] name = "winapi" -version = "0.1.17" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 094424d8f..65da37271 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,17 +10,20 @@ name = "cargo" path = "src/cargo/lib.rs" [dependencies] +advapi32-sys = "0.1" curl = "0.2" docopt = "0.6" env_logger = "0.3" +filetime = "0.1" flate2 = "0.2" git2 = "0.2" git2-curl = "0.2" glob = "0.2" +kernel32-sys = "0.1" libc = "0.1" libgit2-sys = "0.2" log = "0.3" -num_cpus = "0.1" +num_cpus = "0.2" regex = "0.1" registry = { path = "src/registry" } rustc-serialize = "0.3" @@ -31,12 +34,7 @@ threadpool = "0.1" time = "0.1" toml = "0.1" url = "0.2" -filetime = "0.1" - -[target.i686-pc-windows-gnu] -dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" } -[target.x86_64-pc-windows-gnu] -dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" } +winapi = "0.1" [dev-dependencies] tempdir = "0.3" diff --git a/Makefile.in b/Makefile.in index eb4b33888..63728b296 100644 --- a/Makefile.in +++ b/Makefile.in @@ -53,6 +53,19 @@ BIN_TARGETS := cargo BIN_TARGETS := $(BIN_TARGETS:src/bin/%.rs=%) BIN_TARGETS := $(filter-out cargo,$(BIN_TARGETS)) +ifdef CFG_MSVC_INCLUDE_PATH +export INCLUDE := $(CFG_MSVC_INCLUDE_PATH) +endif +ifdef CFG_MSVC_LIB_PATH +export LIB := $(CFG_MSVC_LIB_PATH) +endif +ifdef CFG_MSVC_BIN +export PATH := $(CFG_MSVC_BIN):$(PATH) +endif +ifdef CFG_MSVC_WINDOWS_SDK_DIR +export PATH := $(CFG_MSVC_WINDOWS_SDK_DIR):$(PATH) +endif + define DIST_TARGET ifdef CFG_ENABLE_OPTIMIZE TARGET_$(1) = $$(TARGET_ROOT)/$(1)/release diff --git a/configure b/configure index 0ab442f86..a7f9881f2 100755 --- a/configure +++ b/configure @@ -369,6 +369,52 @@ if [ "$CFG_SRC_DIR" != "$CFG_BUILD_DIR" ]; then err "cargo does not currently support an out-of-tree build dir" fi +for i in $CFG_TARGET +do + case $i in + x86_64-*-msvc) + # Use the REG program to figure out where VS is installed + # We need to figure out where cl.exe and link.exe are, so we do some + # munging and some probing here. We also look for the default + # INCLUDE and LIB variables for MSVC so we can set those in the + # build system as well. + install=$(reg QUERY \ + 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0' \ + -v InstallDir) + need_ok "couldn't find visual studio install root" + CFG_MSVC_ROOT=$(echo "$install" | grep InstallDir | sed 's/.*REG_SZ[ ]*//') + CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT") + CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT") + CFG_MSVC_BIN="${CFG_MSVC_ROOT}/VC/bin/amd64" + CFG_MSVC_CL="${CFG_MSVC_BIN}/cl.exe" + CFG_MSVC_LIB="${CFG_MSVC_BIN}/lib.exe" + CFG_MSVC_LINK="${CFG_MSVC_BIN}/link.exe" + + vcvarsall="${CFG_MSVC_ROOT}/VC/vcvarsall.bat" + CFG_MSVC_INCLUDE_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %INCLUDE%") + need_ok "failed to learn about MSVC's INCLUDE" + CFG_MSVC_LIB_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %LIB%") + need_ok "failed to learn about MSVC's LIB" + CFG_MSVC_WINDOWS_SDK_DIR=$(cmd /c \ + "\"$vcvarsall\" amd64 && cmd /c echo %WindowsSdkDir%") + need_ok "failed to learn about MSVC's WindowsSdkDir" + export CFG_MSVC_WINDOWS_SDK_DIR="${CFG_MSVC_WINDOWS_SDK_DIR}bin/x64" + + putvar CFG_MSVC_ROOT + putvar CFG_MSVC_BIN + putvar CFG_MSVC_CL + putvar CFG_MSVC_LIB + putvar CFG_MSVC_LINK + putvar CFG_MSVC_INCLUDE_PATH + putvar CFG_MSVC_LIB_PATH + putvar CFG_MSVC_WINDOWS_SDK_DIR + ;; + + *) + ;; + esac +done + if [ ! -z "$CFG_ENABLE_NIGHTLY" ]; then if [ ! -f .cargo/config ]; then mkdir -p .cargo diff --git a/src/etc/dl-snapshot.py b/src/etc/dl-snapshot.py index 97e394fa3..a7f8c1907 100644 --- a/src/etc/dl-snapshot.py +++ b/src/etc/dl-snapshot.py @@ -72,7 +72,7 @@ triple = "%s-%s-%s" % (arch, vendor, target_os) hash = snaps[date][platform] tarball = 'cargo-nightly-' + triple + '.tar.gz' -url = 'https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/%s/%s' % \ +url = 'https://static.rust-lang.org/cargo-dist/%s/%s' % \ (date.strip(), tarball) dl_path = "target/dl/" + tarball dst = "target/snapshot" -- 2.30.2